import { reqHospitalDepartment, reqHospitalDetail } from "@/api/hospital";
import { defineStore } from "pinia";
import { DetailState } from "./interface";
import {
  HospitalDepartmentRes,
  HospitalDetail,
  HospitalDetailRes,
} from "@/api/hospital/type";

const useDetailStore = defineStore("Detail", {
  state: (): DetailState => {
    return {
      hospitalInfo: {} as HospitalDetail, //这里只能先类型断言
      hospitalDepartment: [],
    };
  },
  actions: {
    // 获取医院详情的方法
    async getHospitalDetail(hoscode: string) {
      let res: HospitalDetailRes = await reqHospitalDetail(hoscode);
      this.hospitalInfo = res.data;
    },
    async getHospitalDepartment(hoscode: string) {
      let res: HospitalDepartmentRes = await reqHospitalDepartment(hoscode);
      this.hospitalDepartment = res.data;
    },
  },
  getters: {},
});

// 对外暴露获取仓库的方法
export default useDetailStore;
